package jok.serial;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

import jok.io.FileDemo;

public class ObjectInputStreamDemo {

	public static void main(String[] args) {

		// ObjectOutputStreamDemo.writeObj();

		// readObj();

		ObjectOutputStreamDemo.writeObjList();

		readObjList();

		FileDemo.deleteFile("D:/a.txt");
	}

	public static void readObj() {
		ObjectInputStream ois = null;
		try {
			ois = new ObjectInputStream(new FileInputStream("D:/a.txt"));
			Student stu = (Student) ois.readObject();
			System.out.println(stu);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			try {
				if (ois != null)
					ois.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void readObjList() {
		ObjectInputStream ois = null;
		try {
			ois = new ObjectInputStream(new FileInputStream("D:/a.txt"));
			List<Student> list = (ArrayList<Student>) ois.readObject();
			System.out.println(list);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			try {
				if (ois != null)
					ois.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
